package com.thoughtworks.recruit.test.jgraph.graph.operations;

import com.thoughtworks.recruit.test.jgraph.graph.EdgeSetFactory;
import com.thoughtworks.recruit.test.util.ArraySetUtil;

import java.io.Serializable;
import java.util.Set;

/**
 * An edge set factory which creates {@link ArraySetUtil} of size 1, suitable for small degree
 * vertices.
 *
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 *
 */
public class ArraySetEdgeSetFactory<V, E>
    implements EdgeSetFactory<V, E>, Serializable
{
    private static final long serialVersionUID = 1L;

    /**
     * {@inheritDoc}
     */
    @Override
    public Set<E> createEdgeSet(V vertex)
    {
        // NOTE: use size 1 to keep memory usage under control
        // for the common case of vertices with low degree
        return new ArraySetUtil<>(1);
    }
}